package com.cn.controller;

import com.cn.pojo.TzCategory;
import com.cn.service.CategoryService;
import com.cn.utils.RequestPage;
import com.cn.utils.ResponseEnum;
import com.cn.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 商品分类信息
 */
@RestController
@RequestMapping("/prod/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;


    /**
     * 分页查询
     * @param requestPage
     * @return
     */
    @PostMapping("/categoryPage")
    public Result categoryPage(@RequestBody RequestPage requestPage){
        List<TzCategory> tzCategories =
                categoryService.categoryPage(requestPage);
        return Result.success(tzCategories);
    }




    /**
     * 根据父节点查询子节点方式
     * @param id
     * @return
     */
    @GetMapping("/categoryById/{id}")
    public Result categoryById(Integer id){
        List<TzCategory> tzCategories=  categoryService.categoryById(id);
        return Result.success(tzCategories);
    }

    /**
     * 查询父节点信息
     * @return
     */
    @GetMapping("/cateParent")
    public Result cateParent(){
        List<TzCategory> tzCategories= categoryService.cateParent();
        return Result.success(tzCategories);
    }

    /**
     * 添加分类信息
     * @param tzCategory
     * @return
     */
    @PostMapping("/addCategory")
    public Result addCategory(@RequestBody TzCategory tzCategory){
        Integer i = categoryService.addCategory(tzCategory);
        return Result.success(ResponseEnum.SUCCESSCODE);
    }



}
